package T4.EjemplosDeIO;


import java.io.*;

public class Ejemplo3 {

    static public void main(String[] args) {
        File file1 = new File("C:/a/datos.dat");
        File file2 = new File("C:/a/objetos.dat");
        FileInputStream fileInputStream = null, fileInputStream2 = null;
        DataInputStream dataInputStream = null;
        ObjectInputStream objectInputStream = null;

        try {
            fileInputStream = new FileInputStream(file1);
            dataInputStream = new DataInputStream(fileInputStream);

            System.out.println(dataInputStream.readBoolean());
            System.out.println(dataInputStream.readInt());
            System.out.println(dataInputStream.readDouble());
            fileInputStream2 = new FileInputStream(file2);
            objectInputStream = new ObjectInputStream(fileInputStream2);
            System.out.println(objectInputStream.readObject());

        } catch (Exception ex) {
            System.out.println("Se ha producido un error antes de terminar las escrituras");
            ex.printStackTrace();
        } finally {
            if (dataInputStream != null) {
                try {
                    dataInputStream.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
            if (fileInputStream != null) {
                try {
                    fileInputStream.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
            if (objectInputStream != null) {
                try {
                    objectInputStream.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
            if (fileInputStream2 != null) {
                try {
                    fileInputStream2.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }
    }
}
